home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / jcool01.zip / BASE_MAT.C < prev    next >
C/C++ Source or Header  |  1992-08-26  |  5KB  |  123 lines

  1. //
  2. // Copyright (C) 1991 Texas Instruments Incorporated.
  3. //
  4. // Permission is granted to any individual or institution to use, copy, modify,
  5. // and distribute this software, provided that this complete copyright and
  6. // permission notice is maintained, intact, in all copies and supporting
  7. // documentation.
  8. //
  9. // Texas Instruments Incorporated provides this software "as is" without
  10. // express or implied warranty.
  11. //
  12. // Created: MBN 09/11/89 -- Initial design and implementation
  13. // Updated: MJF 03/12/90 -- Added group names to RAISE
  14. // Updated: VDN 02/21/92 -- New lite version
  15. //
  16. // The parameterized CoolMatrix<Type>  class is publicly   derived from the  CoolBase_Matrix
  17. // class and implements two dimensional arithmetic matrices of a user specified
  18. // type.   This is accompilshed by using  the parameterized  type capability of
  19. // C++.  The only constraint placed on the type  is  that it must  overload the
  20. // following operators: +, -,  *,  and /. Thus, it will  be possible to have  a
  21. // matrix of  type Complex.  The CoolMatrix<Type> class  is static in size, that is
  22. // once a  CoolMatrix<Type> of  a particular  size has been   declared, there is no
  23. // dynamic growth or resize method available.
  24. //
  25. // The CoolBase_Matrix class is the base class for the parameterized  CoolMatrix<Type> class
  26. // and implements all non-type specific functionality. The private data section
  27. // contains two slots to maintain  the row  and column specification. There are
  28. // two constructors  for  the CoolBase_Matrix  class. The   first   takes  two arguments
  29. // specifying the number of rows and columns. The second takes a reference to a
  30. // CoolBase_Matrix object and  reproduces its state. There  are  two public methods that
  31. // provide accessors to the row  and column slots.  Finally, there are  several
  32. // private  methods  that  are called   by the   parameterized class to  handle
  33. // exceptions.
  34.  
  35. #ifndef BASE_MATRIXH                // If no CoolBase_Matrix class,
  36. #include <cool/Base_Matrix.h>            // Include header file
  37. #endif    
  38.  
  39. // CoolBase_Matrix -- Constructor specifiying size of matrix
  40. // Input:    Row, Column parameters
  41. // Output:   None
  42.  
  43. CoolBase_Matrix::CoolBase_Matrix (int row, int col) {
  44. #if ERROR_CHECKING
  45.   if (row <= 0)    {                // If invalid size specified
  46.     //RAISE (Error, SYM(CoolBase_Matrix), SYM(Invalid_Row),
  47.     printf ("CoolBase_Matrix::CoolBase_Matrix(): Invalid size %d specified for row.\n", row);
  48.     abort ();
  49.   }
  50.   if (col <= 0)    {                // If invalid size specified
  51.     //RAISE (Error, SYM(CoolBase_Matrix), SYM(Invalid_Col),
  52.     printf ("CoolBase_Matrix::CoolBase_Matrix(): Invalid size %d specified for column.\n", col);
  53.     abort ();
  54.   }
  55. #endif
  56.   this->num_rows = row;                // Save row count
  57.   this->num_cols = col;                // Save column count
  58. }
  59.  
  60.  
  61. // CoolBase_Matrix -- constructor for reference to another CoolBase_Matrix object
  62. // Input:    CoolBase_Matrix reference
  63. // Output:   None
  64.  
  65. CoolBase_Matrix::CoolBase_Matrix (const CoolBase_Matrix& m) {
  66.   this->num_rows = m.num_rows;            // Copy row size
  67.   this->num_cols = m.num_cols;            // Copy column size
  68. }
  69.  
  70.  
  71. // CoolBase_Matrix -- Destructor for CoolBase_Matrix
  72. // Input:    None
  73. // Output:   None
  74.  
  75. CoolBase_Matrix::~CoolBase_Matrix () {;}
  76.  
  77.  
  78. // row_index_error -- Raise exception for invalid row index.
  79. // Input:           function string, type string, row specification
  80. // Output:          None
  81.  
  82. void CoolBase_Matrix::row_index_error (const char* fcn, const char* type, int r) const {
  83.   //RAISE (Error, SYM(CoolBase_Matrix), SYM(Invalid_Row),
  84.   printf ("CoolBase_Matrix<%s>::%s: Invalid value %d specified for row.\n", 
  85.       type, fcn, r);
  86.   abort ();
  87. }
  88.  
  89.  
  90. // col_index_error -- Raise exception for invalid col index.
  91. // Input:           function string, type string, column specification
  92. // Output:          None
  93.  
  94. void CoolBase_Matrix::col_index_error (const char* fcn, const char* type, int c) const {
  95.   //RAISE (Error, SYM(CoolBase_Matrix), SYM(Invalid_Col),
  96.   printf ("CoolBase_Matrix<%s>::%s: Invalid value %d specified for column.\n", 
  97.       type, fcn, c);
  98.   abort ();
  99. }
  100.  
  101. // dimension_error -- Raise exception for invalid dimensions
  102. // Input:           function string, type string, rowXcol,rowXcol
  103. // Output:          None
  104.  
  105. void CoolBase_Matrix::dimension_error (const char* fcn, const char* type, 
  106.                   int r1, int c1, int r2, int c2) const {
  107.   //RAISE (Error, SYM(CoolBase_Matrix), SYM(Invalid_Dim),
  108.   printf ("CoolBase_Matrix<%s>::%s: Dimensions [%d,%d] and [%d,%d] do not match.\n", 
  109.       type, fcn, r1, c1, r2, c2);
  110.   abort ();
  111. }
  112.  
  113. // va_arg_error -- Raise exception for using class objects, or chars in (...)
  114. // Input:          Type string
  115. // Output:         None
  116.  
  117. void CoolBase_Matrix::va_arg_error (const char* Type, int n) {
  118.   //RAISE (Error, SYM(CoolBase_Matrix), SYM(Invalid_Va_Arg),
  119.   printf ("CoolBase_Matrix<%s>::CoolBase_Matrix<%s>(): Invalid type in ... or wrong alignment with %d bytes.\n",
  120.       Type, Type, n);
  121.   abort ();
  122. }
  123.